<template>
  <ant-modal
    modalWidth="800"
    modalHeight="600"
    :visible="open"
    modal-title="选择配件单"
    :adjust-size="true"
    @cancel="cancel"
  >
    <a-row slot="content">
      
      <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="8" >
              <a-form-item label="单据编号">
                <a-input v-model="queryParam.accessoryNumber" placeholder="请输入单据编号" allow-clear @keyup.enter.native="handleQuery"/>
              </a-form-item>
            </a-col>
            <a-col :span="8" >
              <a-form-item label="单据日期">
                <a-date-picker
                  v-model="queryParam.beginaccessoryDate"
                  valueFormat="YYYY-MM-DD"
                  :show-today="true"
                  placeholder="选择日期"
                  style="width: 100%"
                />
              </a-form-item>
            </a-col>
            <a-col :span="8" >
              <a-form-item label="地址">
                <a-input v-model="queryParam.address" placeholder="请输入地址" allow-clear @keyup.enter.native="handleQuery"/>
              </a-form-item>
            </a-col>
            <a-col :span="8" v-if="advanced">
              <a-form-item label="电话">
                <a-input v-model="queryParam.phone" placeholder="请输入电话" allow-clear @keyup.enter.native="handleQuery"/>
              </a-form-item>
            </a-col>
            <a-col>
              <span class="table-page-search-submitButtons" style="float: right;">
                <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      <advance-table
        tableKey="base-bizProductionProcess-index-table"
        @change="handleTableChange"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="list"
        :loading="loading"
        :format-conditions="true"
        :row-selection="{ selectedRowKeys: selectedRowKeys,onChange: onSelectChange,type: 'radio' }"
      >
      </advance-table>
    </a-row>
    <template slot="footer">
      <a-button :disabled="disabled" @click="cancel">
        取消
      </a-button>
      <a-button type="primary" :disabled="disabled" @click="confirm(true)">
        确定
      </a-button>
    </template>
  </ant-modal>
</template>
<script>

import { listBizParts } from '@/api/biz/bizParts'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
import AntModal from '@/components/pt/dialog/AntModal'
export default {
  name: 'BizAccessoryListForm',
  components: {
    AdvanceTable,
    AntModal
  },
  data () {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 测量单数据
      list: [],
      // 查询参数
      queryParam: {
        status:0
      },
      
      columns: [
        {
          title: '单据编号',
          dataIndex: 'accessoryNumber',
          ellipsis: true,
          align: 'left'
        },
        {
          title: '单据日期',
          dataIndex: 'createTime',
          align: 'center'
        },
        {
          title: '地址',
          dataIndex: 'address',
          ellipsis: true,
          align: 'left',
          
        },
        {
          title: '电话',
          dataIndex: 'phone',
          ellipsis: true,
          align: 'left',
          
        },
        {
          title: '备注',
          dataIndex: 'remark',
          ellipsis: true,
          align: 'left',
          
        },

        {
          title: '操作',
          dataIndex: 'operation',
          align: 'center',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      open: false,
      closeDialog: true,
      spinning: false,
      delayTime: 100,
      disabled: false,
      id: undefined
    }
  },
  created () {
  },
  methods: {
    
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        accessoryNumber: undefined,
        status:'0',
        beginaccessoryDate: undefined,

        address: undefined,

        phone: undefined

      }
      this.handleQuery()
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 查询生产工序列表 */
    getList () {
      this.loading = true
      listBizParts(this.queryParam).then(response => {
        this.list = response.data.list
        this.loading = false
      })
    },

    handleTableChange (pagination, filters, sorter) {
      if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') {
        this.queryParam.orderByColumn = 'a.' + sorter.field
        this.queryParam.isAsc = sorter.order
      }
      this.getList()
    },
    /** 修改按钮操作 */
    handleChooseAccessory (row) {
      this.open = true;
      if (row.address) {
        this.$set(this.queryParam,'address',row.address)
      }
      this.getList();
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.id)
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.$emit('close')
    },
    /** 提交按钮 */
    confirm: function (closeDialog) {
      // this.closeDialog = closeDialog
      this.disabled = true
      if(this.selectedRowKeys.length==0) {
        this.$message.warning('请选择测量单');
        this.disabled = false
        return false
      } else {
        this.open = false
        this.$emit('ok',this.selectedRows);
        this.$emit('close')
        this.disabled = false
      }
    },
  }
}
</script>
